package com.example.literj.kt.schedulers

import com.example.literj.kt.core.Scheduler
import com.example.literj.kt.functions.Supplier
import com.example.literj.kt.internal.schedulers.IoScheduler
import com.example.literj.kt.plugins.RxJavaPlugins

object Schedulers {

    var SINGLE: Scheduler? = null

    var COMPUTATION: Scheduler? = null

    var IO: Scheduler? = null

    var TRAMPOLINE: Scheduler? = null

    var NEW_THREAD: Scheduler? = null

    init {
        // TODO SINGLE = RxJavaPlugins.initScheduler(SingleTask())

        // TODO COMPUTATION = RxJavaPlugins.initScheduler(ComputationTask())

        IO = RxJavaPlugins.initScheduler(IOTask())

        // TODO TRAMPOLINE = TrampolineScheduler.instance()

        // TODO NEW_THREAD = RxJavaPlugins.initScheduler(NewThreadTask())
    }

    @JvmStatic
    fun io(): Scheduler {
        return RxJavaPlugins.initScheduler(IO!!)
    }

    internal object IoHolder {
        val DEFAULT: Scheduler = IoScheduler(null)
    }

    internal class IOTask : Supplier<Scheduler> {
        override fun get(): Scheduler {
            return IoHolder.DEFAULT
        }
    }
}